<?php
	define('RIGHT_ACCESS', true);
	define('ROOT_FOLDER', './');

	include_once(ROOT_FOLDER.'includes/xml_func.php');
	include_once(ROOT_FOLDER.'includes/text_func.php');
	// Start XML
	XML::start();
	// No request reference
	$error = false;
	$error_string = 'error.request.invalid';
	if (!isset($_POST['r']))
	{
		$error_string = 'error.request.invalid';
		$error = true;
	}
	if (!$error)
	{
		// API redirect system
		$api = array(
			//Test
			'test' => 'user/auth.php',

			// User handle
			'login' => 'user/login.php',
			'logout' => 'user/logout.php',
			'register' => 'user/register.php',

			// Project
			'create_project' => 'project/create_project.php',
			'get_user_projects' => 'project/get_user_projects.php'
		);

		// Apply API
		$r = trim(htmlspecialchars_decode($_POST['r']));
		if (!array_key_exists($r, $api))
		{
			$error_string = 'error.request.invalid';
			$error = true;
		}
		if (!$error)
			include_once(ROOT_FOLDER.'api/'.$api[$r]);
	}
	// Error
	if ($error)
		XML::write_element('request', $error_string);

	// End XML
	XML::end();
?>